package com.yanqu.road.server.cmd.activity.springunionbanquet;

import com.yanqu.road.entity.log.springunionbanquet.LogSpringUnionBanquetJoin;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SpringUnionBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.springunionbanquet.SpringUnionBanquetMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SPRING_UNION_BANQUET_JOIN_FROM_CROSS, desc = "吃宴（返回）")
public class SpringUnionBanquetJoinFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SpringUnionBanquetProto.CrossSpringUnionBanquetJoinRespMsg respMsg = SpringUnionBanquetProto.CrossSpringUnionBanquetJoinRespMsg.parseFrom(packet.getBytes());

        if(respMsg.getRet() == 0){
            //日志
            AutoLogMgr.add(new LogSpringUnionBanquetJoin(
                    SpringUnionBanquetMgr.getConfig().getActivityId(),
                    packet.getPlayerId(),
                    respMsg.getJoin().getJoinId(),
                    respMsg.getBanquet().getBanquetId(),
                    respMsg.getReward()));

            player.getModule(CurrencyModule.class).addCurrency(respMsg.getReward(), eLogMoneyType.SpringUnionBanquet, eLogMoneyType.SpringUnionBanquetJoinReward);
        }
        SpringUnionBanquetProto.SpringUnionBanquetJoinRespMsg.Builder clientMsg = SpringUnionBanquetProto.SpringUnionBanquetJoinRespMsg.newBuilder();
        clientMsg.setRet(respMsg.getRet());
        clientMsg.setReward(respMsg.getReward());
        if(respMsg.hasBanquet()){
            clientMsg.setBanquet(respMsg.getBanquet());
        }
        player.sendPacket(Protocol.U_SPRING_UNION_BANQUET_JOIN, clientMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
